define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
	    this.loadDone = false;
	    this.catId = 0;
		this.callParent();
	};
	
	Model.prototype.getLeftImageUrl = function(url) {
		return url?this.getParentModel().serverUrl+url:require.toUrl("$UI/CommunityOto/category/img/category_default.png");
	};

	Model.prototype.getImageUrl = function(url) {
		return url?this.getParentModel().serverUrl+url:require.toUrl("$UI/CommunityOto/category/img/loading.jpg");
	};

	Model.prototype.mainMenuDataCustomRefresh = function(event){		         
          var url = this.getParentModel().serverUrl + "/ex_community/a/api/community/getPalmCommunityCategorys?callback=?";
          
          var me = this;
          
          $.getJSON(url,function(catData){
        	  if(catData && catData.length > 0){
        		  event.source.loadData(catData);
        		  me.catId = catData[0].fID;
                  me.comp("list3").refresh(true);
        	  }
        	   
          });
	};
	


	Model.prototype.mainMenuClick = function(event){
		var currentId = this.comp("mainMenuData").getCurrentRowID();
		if(this.catId !== currentId){
			this.comp("infoData").clear();
			this.catId = currentId;
			this.comp("list3").refresh(true);
		}
	};
	Model.prototype.li1Click = function(event){
		var row = event.bindingContext.$object;
		justep.Shell.showPage("$UI/communityOto/category/categoryInfo.w?id="+row.val("id"));
	};
	
	Model.prototype.infoDataCustomRefresh = function(event){
	
		if(event.source.count() < event.offset){
			return ;
		}
		this.comp("popOver1").show();
		var me = this;
		var url = this.getParentModel().serverUrl + "/ex_community/a/api/community/getClassInfosByCategoryId?callback=?";
		var page = event.offset/event.limit + 1;
		$.getJSON(
				url,
				{
				    "category.id":this.catId,
				    'pageSize':event.limit,
				    'pageNo':page
				},
				function(data){
				    if(data && data.data){		
				    	event.source.loadData(data.data,true,null,event.offset,true);
				    	
				    }
				    me.loadDone = true;
				    me.comp("popOver1").hide();
				}
		);
		
		
	};
	Model.prototype.scrollView1PullUp = function(event){
	    if(this.loadDone){
	    	this.loadDone = false;
	    	this.comp("infoData").loadNextPageData();
	    }
		
	};
	
	Model.prototype.scrollView1PullDown = function(event){
	
		this.comp("infoData").refreshData();
		
	};
	
	Model.prototype.infoDataBeforeRefresh = function(event){
		this.loadDone = false;
	};
	
	return Model;
});